#include "newProjectConfigDialog.h"

newProjectConfigDialog::newProjectConfigDialog(QWidget * parent) : QDialog(parent)
{
    this->resize(479, 403);

    buttonBox = new QDialogButtonBox(this);
    buttonBox->setGeometry(QRect(150, 350, 171, 32));
    buttonBox->setOrientation(Qt::Horizontal);
    buttonBox->setStandardButtons(QDialogButtonBox::Cancel 
                                  | QDialogButtonBox::NoButton
                                  | QDialogButtonBox::Ok);

    groupBoxLanguage = new QGroupBox(tr("Project language"), this);
    groupBoxLanguage->setObjectName(QString::fromUtf8("groupBox"));
    groupBoxLanguage->setGeometry(QRect(10, 10, 461, 91));

    radioButtonC = new QRadioButton(tr("C"), groupBoxLanguage);
    radioButtonC->setGeometry(QRect(20, 20, 101, 23));
    radioButtonC->setChecked(true); // coché par défaut

    radioButtonAda = new QRadioButton(tr("Ada"), groupBoxLanguage);
    radioButtonAda->setGeometry(QRect(20, 40, 101, 23));

    radioButtonCpp = new QRadioButton(tr("C++"), groupBoxLanguage);
    radioButtonCpp->setGeometry(QRect(20, 60, 101, 23));

    groupBoxLocation = new QGroupBox(tr("Existing project location"), this);
    groupBoxLocation->setGeometry(QRect(10, 110, 461, 221));

    linePathEdit = new QLineEdit(groupBoxLocation);
    linePathEdit->setGeometry(QRect(40, 60, 321, 23));

    pathCompleter = new QCompleter(linePathEdit);
    pathCompleter->setCaseSensitivity(Qt::CaseInsensitive);
    pathCompleter->setModel(new QDirModel(pathCompleter));
    linePathEdit->setCompleter(pathCompleter);

    radioButtonLocal = new QRadioButton(tr("local directory"), groupBoxLocation);
    radioButtonLocal->setGeometry(QRect(20, 30, 131, 23));
    radioButtonLocal->setChecked(true);

    radioButtonCVS = new QRadioButton(tr("CVS repository"), groupBoxLocation);
    radioButtonCVS->setGeometry(QRect(20, 120, 121, 23));

    dirChooserButton = new QPushButton(tr("Browse"), groupBoxLocation);
    connect(dirChooserButton, SIGNAL(clicked()), this, SLOT(pathFolderProjectChooser()));
    dirChooserButton->setGeometry(QRect(368, 58, 83, 27));

    gotoSVNButton = new QPushButton(tr("SVN"), groupBoxLocation);
    gotoSVNButton->setGeometry(QRect(40, 160, 83, 27));
    gotoSVNButton->setEnabled(false);

    gotoGITButton = new QPushButton(tr("GIT"), groupBoxLocation);
    gotoGITButton->setGeometry(QRect(150, 160, 83, 27));
    gotoGITButton->setEnabled(false);

    connect(buttonBox, SIGNAL(accepted()), this, SLOT(acceptDialog()));
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(skipDialog()));

    this->setWindowTitle(tr("Create new project"));

    connect(this, SIGNAL(selectedPath(QString)), linePathEdit, SLOT(setText(QString)));
    connect(radioButtonLocal, SIGNAL(pressed()), this, SLOT(chooseLocalPathLocation()));
    connect(radioButtonCVS, SIGNAL(pressed()), this, SLOT(chooseCVSPathLocation()));
}

void
newProjectConfigDialog::chooseCVSPathLocation()
{
    gotoSVNButton->setEnabled(true);
    gotoGITButton->setEnabled(true);
    dirChooserButton->setEnabled(false);
    linePathEdit->setEnabled(false);
    emit linePathEdit->setText("");
}

void
newProjectConfigDialog::chooseLocalPathLocation()
{
    gotoSVNButton->setEnabled(false);
    gotoGITButton->setEnabled(false);
    dirChooserButton->setEnabled(true);
    linePathEdit->setEnabled(true);
}

void
newProjectConfigDialog::acceptDialog()
{
    emit create(QString(linePathEdit->text()));
    emit accept();
}

void
newProjectConfigDialog::skipDialog()
{
    emit reject();
}

void
newProjectConfigDialog::pathFolderProjectChooser()
{
 QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
      "/home", QFileDialog::ShowDirsOnly|QFileDialog::DontResolveSymlinks);
    emit selectedPath(dir);

}

newProjectConfigDialog::~newProjectConfigDialog() {

}

